(function($){
	var _ajax = $.ajax;
	$.ajax = function(url,options){
		if ( typeof url === "object" ) {
			options = url;
		}else{
			options = options || {};
			options.url = url;
		}
		//当url地址栏以 “/”开头是自动添加 地址前缀
		if($.ajax.basePath){
			if(options.url.indexOf("/")==0){
				options.url = $.ajax.basePath+options.url;
			}
		}
		
		options = $.extend({
			type : "get",
			showMask:true,
			waitMsg:null,
			successMsg:null,
			errorMsg:null
		},options);
		
		var dealOptions={
			success : function(data, textStatus) {
				if(options._progress){
					Ctj.closeProgress(options._progress);
				}
				if (typeof options.success === "function") {
					return options.success.apply(this,arguments);
				} else {
					if(!options.complete){
						Ctj.alert(options.successMsg|| "调用成功");
					}
				}
			},
			// 加载等待中
			beforeSend : function() {
				if (typeof options.beforeSend === "function") {
					if(options.beforeSend.apply(this,arguments)===false){
						return false;
					}
				}
				if(options.showMask&&(options.waitMsg||$.ajax.waitMsg)){
					options._progress= Ctj.showProgress({
						title:"提示",
						msg:options.waitMsg||$.ajax.waitMsg,
						interval:500
					});
				}
			},
			error : function(XMLHttpRequest, textStatus,errorThrown) {
				if(options._progress){
					Ctj.closeProgress(options._progress);
				}
				if (typeof options.error === "function") {
					return options.error.apply(this,arguments);
				}else{
					var error = $.ajax.parseError(XMLHttpRequest, textStatus,errorThrown);
					Ctj.error(error);
				}
			}
			
		}
		return _ajax($.extend({},options,dealOptions));
	};
	
	$.ajax.basePath=null;
	$.ajax.waitMsg=null;
	$.ajax.parseError=function(XMLHttpRequest, textStatus,errorThrown){
		var error="";
		if (XMLHttpRequest.status == "404") {
			error = "404 不存在当前请求地址：";
		} else if(XMLHttpRequest.status == "417"||XMLHttpRequest.status == "500"){
			error = XMLHttpRequest.responseText ? (XMLHttpRequest.responseText.substring(0, 300)):"程序异常";
		} else {
			var s = "请求失败，错误代码"+XMLHttpRequest.status+"。"
			error = XMLHttpRequest.responseText ? (s+XMLHttpRequest.responseText.substring(0, 300)):s+"请稍后重试...";
		}
		return error;
	}
})(jQuery);